<template>

	<view class="">
		<view v-for="(item,index) in list" :key="index"  class="time_box">
			<view class="time_box_title">
				<view class="time_box_title_left">
					<image src="./inde_png/index_icon_8.png" class="miaosha" mode=""></image>
					<view v-if="item.end_time<0 && item.start_time>0" class="time_box_title_left_time">
						<image src="./inde_png/index_icon_9.png" class="fire" mode=""></image>
						<u-count-down color="#fff" bg-color="#2E3139" separator-color="#fff" font-size="26" :show-hours="true" :timestamp="-item.end_time"></u-count-down>
						<!-- <span style="color: #fff;font-size: 24rpx;">后结束</span> -->
					</view>
					<view v-if="item.start_time<0" class="time_box_title_left_time">
						<image src="./inde_png/index_icon_9.png" class="fire" mode=""></image>
						<u-count-down color="#fff" bg-color="#2E3139" separator-color="#fff" font-size="26" :show-hours="true" :timestamp="-item.start_time"></u-count-down>
					</view>
				</view>
				<view class="time_box_title_right">
					大牌底价秒杀
					<u-icon name="arrow-right" color="#545458" size="24"></u-icon>
				</view>
			</view>
			<view class="miaosha_list">
				<scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
					<view v-for="(ite , ind) in item.seckill_goods" :key="ind" @click="toGood( ite , index)" class="scroll-view-item_H">
						<view class="item_H_box">
							<image class="goods_item_box" :src="to_pic(ite.goods.pic)" :lazy-load="true" mode=""></image>
							<view class="price_box">
								<view class="price_box_left">
									¥{{ite.seckill_price}}
								</view>
								秒杀
							</view>
							<view class="scroll-view-item_H_title uni-ellipsis">
								{{ite.goods.name}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
	
</template>

<script>
	import mImg from '@/componts/m-img/index.vue';
	export default {
		components: {
			mImg
		},
		props: {
			// 缺省图
			list: {
				type: Array,
				default: []
			},
			row: {
				type: Object,
				default: () => ({})
			},
			style_item: {
				type: Object,
				default: () => ({
					background: 'rgba(251, 245, 238 , 1)'
				})
			},

		},
		mounted() {
			this.clearTimer().then(res=>{
				this.startTimer()
			})
		},
		beforeDestroy() {
			this.clearTimer()
		},
		data() {
			return {
				timestamp: 3600,
				number: 0,
				timer: null, // 存储定时器ID
				count: 0
			}
		},
		methods: {
			startTimer() {
				this.timer = setInterval(() => {
					this.count++
					this.clear()
				}, 5000) // 每秒执行一次
			},
			clearTimer() {
				return new Promise((resolve, reject) => {
					if (this.timer) {
						clearInterval(this.timer)
						this.timer = null
						resolve()
					}else{
						resolve()
					}
				})
				
			},
			clear(){
				this.$wqzApi.seckill_goods_sold({}).then(res=>{
					this.$emit('list_chagne' , res.data.data)
				})
			},
			number_zhe(price1, price2) {
				var number = price1 / price2
				number = number.toFixed(2)
				number = Number(number) * 10
				number = number.toFixed(1)
				return number == 'Infinity' ? 0 : number
			},
			number_bai(price1, price2) {
				console.log(price1, price2)
				if (price1 > 0) {
					var number = price1 / price2
					number = number.toFixed(2)
					number = 1 - Number(number)
					number = Number(number) * 100
					number = number.toFixed(2)
				} else {
					var number = 100
				}


				return number == 'Infinity' ? 0 : number
			},
			toGood( ite , index) {
				uni.navigateTo({
					url: `/pages/shop_info/shop_info?id=${ite.goods.id}&seckill_id=${this.row.data[index].id}&seckill_goods_id=${ite.id}`
				})
			},
			to_pic(url) {
				var pic = url.split(",")
				return pic[0]
			}

		}
	}
</script>

<style lang="scss" scoped>
	@import url(./shop_time_goods.css);

	.index_Title_box {
		padding: 18rpx;
		font-size: 36rpx;
		font-weight: 800;
	}
</style>